package cn.ibizlab.odoo.core.odoo_base.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ires_lang;
import cn.ibizlab.odoo.core.odoo_base.domain.Res_lang;
import cn.ibizlab.odoo.core.odoo_base.filter.Res_langSearchContext;
import cn.ibizlab.odoo.core.odoo_base.service.IRes_langService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[语言] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Res_langServiceImpl implements IRes_langService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ires_langClientService res_langClientService;

    @Override
    public void updateBatch(List<Res_lang> res_langs, int batchSize) {

        //res_langClientService.updateBatch(res_langs,batchSize) ;

    }

    @Override
    public boolean update(Res_lang res_lang) {
        boolean bOk = false ;
        Ires_lang clientModel = this.convert2Model(res_lang,null);
        res_langClientService.update(clientModel) ;
        this.convert2Domain(clientModel,res_lang) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Res_lang res_lang) {
        boolean bOk = false ;
        Ires_lang clientModel = this.convert2Model(res_lang,null);
        res_langClientService.create(clientModel) ;
        this.convert2Domain(clientModel,res_lang);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ires_lang clientModel = res_langClientService.createModel();
        clientModel.setId(id);
        res_langClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //res_langClientService.removeBatch(res_langs) ;

    }

    @Override
    public void createBatch(List<Res_lang> res_langs, int batchSize) {

                        //res_langClientService.createBatch(res_langs,batchSize) ;

    }

    @Override
    public Res_lang get(Integer id) {
        Ires_lang clientModel = res_langClientService.createModel();
        clientModel.setId(id);
        res_langClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Res_lang get(Res_lang res_lang) {
        Res_lang retres_lang = this.get(res_lang.getId()) ;
    	BeanCopier copier=BeanCopier.create(retres_lang.getClass(), res_lang.getClass(), false);
        copier.copy(retres_lang, res_lang, null);
        return res_lang ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Res_lang> searchDefault(Res_langSearchContext context) {
        List<Res_lang> list = new ArrayList<Res_lang>();
        Page<cn.ibizlab.odoo.core.client.model.Ires_lang> clientModelList = res_langClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ires_lang clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Res_lang>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Res_lang> selectByOdoo_create(Integer id){
        Res_langSearchContext context = new Res_langSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Res_lang> list = new ArrayList<Res_lang>();
        Page<cn.ibizlab.odoo.core.client.model.Ires_lang> clientModelList = res_langClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ires_lang clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Res_lang>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Res_lang> selectByOdoo_write(Integer id){
        Res_langSearchContext context = new Res_langSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Res_lang> list = new ArrayList<Res_lang>();
        Page<cn.ibizlab.odoo.core.client.model.Ires_lang> clientModelList = res_langClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ires_lang clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Res_lang>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ires_lang convert2Model(Res_lang domain , Ires_lang model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = res_langClientService.createModel() ;
        }

         if(domain.getTranslatableDirtyFlag())
            model.setTranslatable(domain.getTranslatable());
         if(domain.getThousands_sepDirtyFlag())
            model.setThousands_sep(domain.getThousands_sep());
         if(domain.getIso_codeDirtyFlag())
            model.setIso_code(domain.getIso_code());
         if(domain.getDecimal_pointDirtyFlag())
            model.setDecimal_point(domain.getDecimal_point());
         if(domain.getGroupingDirtyFlag())
            model.setGrouping(domain.getGrouping());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getDirectionDirtyFlag())
            model.setDirection(domain.getDirection());
         if(domain.getDate_formatDirtyFlag())
            model.setDate_format(domain.getDate_format());
         if(domain.getTime_formatDirtyFlag())
            model.setTime_format(domain.getTime_format());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCodeDirtyFlag())
            model.setCode(domain.getCode());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWeek_startDirtyFlag())
            model.setWeek_start(domain.getWeek_start());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Res_lang convert2Domain( Ires_lang model ,Res_lang domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Res_lang();
        }

        if(model.getTranslatableDirtyFlag())
            domain.setTranslatable(model.getTranslatable());
        if(model.getThousands_sepDirtyFlag())
            domain.setThousands_sep(model.getThousands_sep());
        if(model.getIso_codeDirtyFlag())
            domain.setIso_code(model.getIso_code());
        if(model.getDecimal_pointDirtyFlag())
            domain.setDecimal_point(model.getDecimal_point());
        if(model.getGroupingDirtyFlag())
            domain.setGrouping(model.getGrouping());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getDirectionDirtyFlag())
            domain.setDirection(model.getDirection());
        if(model.getDate_formatDirtyFlag())
            domain.setDate_format(model.getDate_format());
        if(model.getTime_formatDirtyFlag())
            domain.setTime_format(model.getTime_format());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCodeDirtyFlag())
            domain.setCode(model.getCode());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWeek_startDirtyFlag())
            domain.setWeek_start(model.getWeek_start());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
